mui.init();

//获取本地信息
var my_phone = localStorage.getItem("my_phone");
var user_id = localStorage.getItem("user_id");
var mask = mui.createMask(); //遮罩层
//全局变量
var is_realname, status_user, receiver_state, user_phone; //实名状态
//底部菜单栏的页面跳转
//去购物车
//返回user页面
//关闭当前页面，返回上一个页面
mui('body').on('tap', '.go_index', function() {
	window.top.location.href = '../../index.html';
});


//热销商品
var listTui = [];
function commodity() {
//	plus.nativeUI.showWaiting("加载中...");
//	mask.show(); //显示遮罩层	
	mui.ajax(goods_url + '/api/index/index', {
		dataType: 'json', //服务器返回json格式数据
		type: 'post', //HTTP请求类型
		timeout: 10000, //超时时间设置为10秒；
		success: function(data) {
			console.log(JSON.stringify(data))			
			plus.nativeUI.closeWaiting(); //关闭等待
			mask.close(); //关闭遮罩层
			if(data.code == 100) {
      			//银饰专区
				var html = ""
				var hotShop = data.resp.silverZoneList;
				console.log('银饰专区');
				console.log(JSON.stringify(data.resp.silverZoneList));
				for(var i = 0; i < hotShop.length; i++) {
					html += '<li class="recommended  mui-col-xs-6" commodity_id=' + hotShop[i].goods_id + '>';
					if(hotShop[i].album_picture==null){
						html += '<img width="100%" src="images/index_new_hot1.png">';
					}
					else{
						html += '<img width="100%" style="height:130px" src=' + goods_url + hotShop[i].album_picture.pic_cover + '>';
					}					
					html += '<div>';
					html += '<span>' + hotShop[i].goods_name + '</span>';
					html += '<p>¥<span>' + hotShop[i].price + '</span></p>';
					html += '</div>';
					html += '</li>'
				}
				$("#index_new_hot").html(html);						    
			}
		},
		error: function(xhr, type, errorThrown) { //异常处理；
			console.log('热销商品接口失败');
		}
	});
}
//银饰商品
mui("body").on("tap", ".recommended", function() {
	plus.nativeUI.showWaiting("加载中...");
	mask.show(); //显示遮罩层
	var commodity_id = $(this).attr("commodity_id");
	mui.openWindow({
		url: "commodity_details.html",
		id: "commodity_details",
		extras: {
			commodity_id: commodity_id
		},
		createNew: true,
		waiting: {
			autoShow: false
		}
	}, mask.close());
});

//页面进入执行方法
window.onload = function() {
	mui.plusReady(function() {
		var gallery = mui('.mui-slider');
		gallery.slider({
			interval: 2000 //自动轮播周期，若为0则不自动播放，默认为0；
		});
		
		var self = plus.webview.currentWebview();
		plus.nativeUI.closeWaiting(); //关闭等待
//		plus.nativeUI.showWaiting("加载中...");
		mask.show(); //显示遮罩层
		commodity(); //热销商品		

	});
}